package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.listener.IClickCancleListener;
import com.keyancompany.zhongbaopingtai.model.FriendModel;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by lyh on 2016/10/12.
 */
public class SearchFriendsAdapter extends ListAdapter<FriendModel> {


    public IClickCancleListener listener;

    public SearchFriendsAdapter(Context ctx, IClickCancleListener listener) {
        super(ctx);
        this.listener = listener;
    }

    @Override
    public int getContentViewId() {
        return R.layout.item_search_friends;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {
        SearchFriendsHolder hold = new SearchFriendsHolder();
        hold.icon = (ImageView) contentView.findViewById(R.id.search_friends_icon);
        hold.name = (TextView) contentView.findViewById(R.id.search_friends_name);
        hold.add = (TextView) contentView.findViewById(R.id.search_friends_add);
        return hold;
    }

    @Override
    public void setItemView(final int position, HolderView contentView, FriendModel item) {

        SearchFriendsHolder hold = (SearchFriendsHolder) contentView;
        hold.name.setText(item.getUsername());
        ImageLoader.getInstance().displayImage(item.getHeadpic(), hold.icon);
        hold.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.clickCancle(position);

            }
        });


    }


    class SearchFriendsHolder extends HolderView {

        ImageView icon;

        TextView name;

        TextView add;
    }
}
